package com.leonardo.persistenceme.metadatahandlers.taghandlers;

import org.xml.sax.Attributes;

import com.leonardo.persistenceme.exceptions.XmlReadingException;

public class FieldTagHandler extends TagHandler {

	protected String innerText;
	
	public String getTagName() {
		return "field";
	}
	
	public void startTag(Attributes attributes){ 
		if(!owner.isTagOpen("bean"))
			throw new XmlReadingException("Incorrect place of tag field");
	}
	
	public void characters(char[] ch, int start, int lenght) {
		StringBuffer innerText = new StringBuffer(lenght); 
		/* Start DEBUG */
		{/*System.out.println("Inside text: ");*/}
		for(int i = start; i < start +  lenght; i++) {
			{/*System.out.println(ch[i]);*/}
			innerText.append(ch[i]);
		}
		{/*System.out.println();*/}
		/* End DEBUG */
		this.innerText = innerText.toString();
	}
	
	public void endTag() { 
		owner.addField(innerText);
	}
	
}
